package com.class05.dao.impl;

import com.class05.dao.StudentDao;
import com.class05.pojo.Student;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.logging.Logger;

//@Service
@Repository
public class StudentDaoImpl implements StudentDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public List<Student> queryAll() {
        String sql = "select id , name , gender , age , " +
                "class as classes from students ;";
        //        BeanPropertyRowMapper帮我们自动映射列和属性值！
        //        要求列名和属性名一致！
        //         不一致   起别名！
        List<Student> students = jdbcTemplate.
                query(sql, new BeanPropertyRowMapper<Student>(Student.class));
//        Logger logger = Logger.getLogger(Test.class);
        System.out.println("studentDao:" + students);
        return students;
    }
}
